// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: GetPassAction.java

package com.market.web.action;

import java.text.DateFormat;
import java.util.Date;

import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.springframework.beans.BeanUtils;

import com.market.bean.Customer;
import com.market.web.form.CustomerForm;
import com.market.web.mail.SendMail;

// Referenced classes of package com.market.web.action:
// BaseAction

public class GetPassAction extends BaseAction2
{

    public GetPassAction()
    {
    }

    public String execute() throws Exception
    {
        long id = getLong("id");
        Customer cus = getCustomerService().FindById(id);
        ActionMessages error = new ActionMessages();
        if (cus == null)
        {
            error
                    .add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage("\u7528\u6237ID\u9519\u8BEF",
                            false));
           // saveErrors(request, error);
            getRequest().setAttribute("id", String.valueOf(id));
            getRequest().setAttribute("question", cus.getQuestion());
            return INPUT;//mapping.getInputForward();
        }
        String answer = getRequest().getParameter("answer");
        if (cus.getQuestion() != null && cus.getAnswer().equals(answer))
        {
            DateFormat f = DateFormat.getDateInstance();
            StringBuffer text = new StringBuffer();
            text.append("\u60A8\u597D!").append("\n\n").append("     ").append("\u4F60\u7684\u5E10\u53F7\u662F:")
                    .append(cus.getId()).append("\n").append("     \u4F60\u7684\u5BC6\u7801\u662F:").append(
                            cus.getPass()).append("\n\n\n\n\n\n").append("                ").append(
                            "\u4E2D\u56FD\u5F13\u5F29\u7F51    ").append(f.format(new Date()));
            SendMail mail = new SendMail();
            mail.setTitle("\u4E2D\u56FD\u5F13\u5F29\u7F51_\u627E\u56DE\u7528\u6237\u5BC6\u7801!");
            mail.setContent(text.toString());
            CustomerForm cusf = new CustomerForm();
            BeanUtils.copyProperties(cus, cusf);
            mail.addCustomer(cusf);
            mail.send();
            ActionMessages message = new ActionMessages();
            message
                    .add(
                            "org.apache.struts.action.GLOBAL_MESSAGE",
                            new ActionMessage(
                                    "\u4F60\u7684\u5BC6\u7801\u5DF2\u7ECF\u53D1\u5230\u60A8\u7684\u7535\u5B50\u90AE\u7BB1,\u8BF7\u67E5\u6536.",
                                    false));
            //saveMessages(request, message);
            return SUCCESS;//mapping.findForward("success");
        }
        else
        {
            getRequest().setAttribute("id", String.valueOf(id));
            getRequest().setAttribute("question", cus.getQuestion());
            error.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(
                    "Sorry!\u95EE\u9898\u56DE\u7B54\u9519\u8BEF!!!", false));
            //saveErrors(request, error);
            return INPUT;//mapping.getInputForward();
        }
    }
}
